﻿/*****************************************************************//**
 * @file    FITKGraphObjectPostModelBase.h
 * @brief   Post graph object for model base.
 *  
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-07-01
 *********************************************************************/

#ifndef __FITKGRAPHOBJECTPOSTMODELBASE_H__
#define __FITKGRAPHOBJECTPOSTMODELBASE_H__

#include "FITKGraphObjectPostBase.h"

#include "FITKVTKGraphAdaptorAPI.h"

// Forward declaration
class QVariant;

class vtkTextProperty;
class vtkLookupTable;
class vtkAlgorithmOutput;
class vtkRenderer;
class vtkDistanceToCamera;

class FITKPolygonSource;
class FITKGraphActor2D;
class FITKDeformFilter;
class FITKMaxMinValueFilter;

namespace Interface
{
    class FITKAbstractStructuralPostVTK;
    class FITKMeshFeatureVTK;
}

namespace Exchange
{
    /**
     * @brief   Post graph object for model base.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2024-07-01
     */
    class FITKVTKGRAPHADAPTORAPI FITKGraphObjectPostModelBase : public FITKGraphObjectPostBase
    {
        // Regist
        FITKGraphObjectRegist(FITKGraphObjectPostModelBase, FITKGraphObjectPostBase);
        FITKCLASS(Exchange, FITKGraphObjectPostModelBase);

    public:
        /**
         * @brief   Destructor.[virtual]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        virtual ~FITKGraphObjectPostModelBase();

        /**
         * @brief   Change the color by the given array type, name and component name.[override]
         * @param   type: The array type( 0: Solid, 1: Points, 2: Cells )[quote]
         * @param   name: The name of the array[quote]
         * @param   compName: The name of the component array[quote]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        void changeField(int& type, QString& name, QString& compName) override;

        /**
         * @brief   Change the color by the given array type, name and component name.[override]
         * @param   type: The array type( 0: Solid, 1: Points, 2: Cells )[quote]
         * @param   name: The name of the array[quote]
         * @param   compIndex: The index of the component array[quote]
         * @param   compName: The name of the component array[quote]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        void changeField(int& type, QString& name, int& compIndex, QString& compName) override;

        /**
         * @brief   Show or hide the labels of the max and min value of the coloring array.[override]
         * @param   visibile: The visibility.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        void setMaxAndMinVisible(bool visibile) override;

        /**
         * @brief   Set the render, which will add this graph object to itself.( for calculating size )[override]
         * @param   render: The FITKGrapgRender
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        void setFITKRender(Comp::FITKGraphRender* render) override;

        /**
         * @brief   Update the actor with the camera normal.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        void updateCameraNormal() override;

        /**
         * @brief   Show or hide graph object.[virtual][override]
         * @param   visibility: The visibility of graph object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        virtual void setVisible(bool visibility) override;

        /**
         * @brief   Set if the graph object can be picked.[virtual][override]
         * @param   isPickable: Pickable
         * @param   dim: The dimision of the pickable object( -1 means the whole graph object )[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        virtual void setPickable(bool isPickable, int dim = -1) override;

        /**
         * @brief   Get the feature data of the post model.[pure virtual]
         * @return  The mesh feature
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-22
         */
        virtual Interface::FITKMeshFeatureVTK* getMeshFeature() = 0;

    protected:
        /**
         * @brief   Constructor.( For copying data )
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        FITKGraphObjectPostModelBase() = default;   

        /**
         * @brief   Constructor.
         * @param   caseData: The case data( If the post data is import with file, the case data maybe nullptr)
         * @param   postData: The input post data object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        FITKGraphObjectPostModelBase(AbaqusData::FITKDataCase* caseData, Core::FITKAbstractDataObject* postData);

        /**
         * @brief   Initialize the labels actors.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        void initializeLabelsActors();

        /**
         * @brief   Update the max-min label and glyph actors' visibility.
         * @param   visibility: The visibility of actors
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        void updateMaxMinActorVisible(bool visibility);

        /**
         * @brief   Create a text actor with the given algorithm output connection.
         * @param   output: The output port
         * @param   textProperty: The text property
         * @param   arrayName: The text label array name
         * @return  The actor 2D
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        FITKGraphActor2D* createTextActor(vtkAlgorithmOutput* output, vtkTextProperty* textProperty, QString arrayName);

        /**
         * @brief   Create a glyph actor with the given algorithm output connection.
         * @param   output: The output port
         * @param   color: The actor color
         * @return  The actor
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        FITKGraphActor* createGlyphActor(vtkAlgorithmOutput* output, QColor color);
 
    protected:
        /**
         * @brief   The max array filter.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        FITKMaxMinValueFilter* m_maxFilter{ nullptr };

        /**
         * @brief   The min array filter.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        FITKMaxMinValueFilter* m_minFilter{ nullptr };

        /**
         * @brief   The max array value label actor. 
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        FITKGraphActor2D* m_fActor2DMax{ nullptr };

        /**
         * @brief   The min array value label actor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        FITKGraphActor2D* m_fActor2DMin{ nullptr };

        /**
         * @brief   The max array value glyph actor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        FITKGraphActor* m_fActorMax{ nullptr };

        /**
         * @brief   The min array value glyph actor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        FITKGraphActor* m_fActorMin{ nullptr };

        /**
         * @brief   The max array value label line actor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        FITKGraphActor* m_fActorLineMax{ nullptr };

        /**
         * @brief   The min array value label line actor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        FITKGraphActor* m_fActorLineMin{ nullptr };

        /**
         * @brief   The text property for max value labels.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        vtkTextProperty* m_textPropertyMax{ nullptr };

        /**
         * @brief   The text property for mion value labels.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        vtkTextProperty* m_textPropertyMin{ nullptr };

        /**
         * @brief   The max and min labels visibility.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-22
         */
        bool m_showMaxAndMin = false;

        /**
         * @brief   The input source of glyph 3d.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        FITKPolygonSource* m_polygonSource{ nullptr };

        /**
         * @brief   Fixed size filters
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        QList<vtkDistanceToCamera*> m_distToCameraList{};

    };
}   // namespace Exchange

#endif // __FITKGRAPHOBJECTPOSTMODELBASE_H__
